﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace MOJsdk
{
    public interface IHost
    {
        #region Vars
        /// <summary>
        /// Return resource dictionary
        /// </summary>
        ResourceDictionary HostResources { get; }

        /// <summary>
        /// Get the class to acess host vars
        /// </summary>
        MojSystem MoJSystem { get; }

        /// <summary>
        /// Main Window that host canvas
        /// </summary>
        Window TheMainWindow
        { get; }

        /// <summary>
        /// Get Main Canvas
        /// </summary>
        Canvas HostCanvas { get; }
        
        /// <summary>
        /// Get Set MainMenu Options
        /// </summary>
        MenuControl MainMenu { get; }
        #endregion

        #region Actions
        /// <summary>
        /// Get focus on MoJ and select a movie if NaN
        /// </summary>
        void ActionFocus();
        /// <summary>
        /// Select the next movie on a list
        /// </summary>
        void SelectNextMovie();
        /// <summary>
        /// Select the previous movie on the list
        /// </summary>
        void SelectPrevMovie();
        /// <summary>
        /// Show the Main movie browser control
        /// </summary>
        void ShowBrowseMovies();
        /// <summary>
        /// Show the control to add and edit movies
        /// </summary>
        void ShowManageMovies();
        /// <summary>
        /// Show the settings window
        /// </summary>
        void ShowSettings();
        /// <summary>
        /// Play the selected movie
        /// </summary>
        void PlaySelectedMovie();
        #endregion

        /// <summary>
        /// Change the host IPanel
        /// </summary>
        /// <param name="Panel"></param>
        void SetMoviePanel(IPanel Panel);

        /// <summary>
        /// Control that handle movie info
        /// </summary>
        /// <param name="CtrlMetaData"></param>
        void SetMetaDataControl(IMetaData CtrlMetaData);

        /// <summary>
        /// Play a file using the OS default program
        /// </summary>
        /// <param name="FilePath">File Path</param>
        void PlayFile(string FilePath);

        /// <summary>
        /// Open the folder in the explorer
        /// </summary>
        /// <param name="Path">Folder Path</param>
        void OpenFolder(string Path);

        /// <summary>
        /// Show the error window with the specific error alert
        /// </summary>
        /// <param name="Reporter">Class with the error details</param>
        void ReportError(ErrorReporter Reporter);

        /// <summary>
        /// Add a new control to the Canvas
        /// </summary>
        /// <param name="Control">Control to be added</param>
        /// <param name="Info">Control Info</param>
        /// <returns></returns>
        WindowControl AddNewUserControl(UserControl Control, WindowControlInfo Info);

        /// <summary>
        /// Show a windows with the selected option
        /// </summary>
        /// <param name="WinTitle">Tile of the window</param>
        /// <param name="Options">Options</param>
        /// <returns>Selected option, -1 if NaN</returns>
        int SelectOptions(string WinTitle, string[] Options);

        /// <summary>
        /// Show a alert message during 2 seconds
        /// </summary>
        /// <param name="Text">Message to be show</param>
        void AddToasts(string Text);

        /// <summary>
        /// Show a Message window
        /// </summary>
        /// <param name="Message">Message</param>
        /// <param name="Title">Window title</param>
        void ShowMessage(string Message, string Title);

        /// <summary>
        /// Search string in collection
        /// </summary>
        /// <param name="query">Query</param>
        void Search(string query);
        
        /// <summary>
        /// Remove any filter or search query
        /// </summary>
        void ResetElements();

        /// <summary>
        /// Set the waiting grid (ZIndex 500) visibility
        /// </summary>
        /// <param name="GridVisibility"></param>
        void SetForegroundGrid(Visibility GridVisibility);

        /// <summary>
        /// Reload movies
        /// </summary>
        void ReloadElementsInfo();

        /// <summary>
        /// Show the Movie details based on the "https://www.themoviedb.org/" ID
        /// </summary>
        /// <param name="MovieCode">Movie ID</param>
        void ShowMovieDetails(string MovieCode);

        #region Styles
        /// <summary>
        /// Load the style for the specific Element
        /// </summary>
        /// <param name="Info">Element Info</param>
        /// <returns></returns>
        Style LoadStyle(ElementInfo Info);
        /// <summary>
        /// Load the style with a sepecific KeyValue
        /// </summary>
        /// <param name="StyleKeyValue"></param>
        /// <returns></returns>
        Style LoadStyle(string StyleKeyValue);
        /// <summary>
        /// Get the Style interface
        /// </summary>
        IStyle HostStyle { get; }
        /// <summary>
        /// Get all avaible styles
        /// </summary>
        /// <returns></returns>
        IList<IStyle> GetStyles();
        /// <summary>
        /// Check if a specific IStyle is avaible
        /// </summary>
        /// <param name="TheStyle"></param>
        /// <returns></returns>
        bool StyleExist(IStyle TheStyle);
        /// <summary>
        /// Search for a MoJStyle file and add it to the project
        /// </summary>
        void InstallStyle();
        #endregion

        #region ToolButtons
        /// <summary>
        /// Get the StackPanel that hold the ToolButtons
        /// </summary>
        StackPanel TopToolBar { get; }
        /// <summary>
        /// Get all the ToolButton avaible
        /// </summary>
        MojToolButtonCollection ToolButtonCollection { get; }
        #endregion

        #region Events
        /// <summary>
        /// Called when a UIElement call Applstyle
        /// </summary>
        event StyleCalledHandlrer OnStyleCalled;
        /// <summary>
        /// Called when a new movie is Selected
        /// </summary>
        event SelectedMovieChangedHandler SelectedMovieChanged;
        void CallEventSelectedMovieChanged(object sender, SelectedMovieChangedArgs e);
        /// <summary>
        /// Called when a new file is selected
        /// </summary>
        event SelectedFileChangedHandler SelectedFileChanged;
        void CallEventSelectedFileChanged(object sender, SelectedFileChangedArgs e);
        /// <summary>
        /// Called when the display panel is changed
        /// </summary>
        event DisplayPanelChangedHandler DisplayPanelChanged;
        void CallEventDisplayPanelChanged(object sender, DisplayPanelChangedArgs e);
        /// <summary>
        /// Called when application is ready
        /// </summary>
        event CallEventHandler LoadCompleted;
        #endregion

        #region TabControlSettings
        /// <summary>
        /// Add a new Tab to settings window
        /// </summary>
        /// <param name="Title">Tab name</param>
        /// <param name="TheControl">Control to be added</param>
        /// <returns></returns>
        MojSettingsTabControItem AddNewSettingsTabItem(string Title, UserControl TheControl);
        /// <summary>
        /// Get all the avaible Setting Tab
        /// </summary>
        /// <returns></returns>
        IList<MojSettingsTabControItem> GetSettingsTabItems();
        /// <summary>
        /// Remove specific Tab from the Setting window
        /// </summary>
        /// <param name="ID"></param>
        /// <returns>False if tab id didnt exist</returns>
        bool RemoveSettingsTabItem(int ID);
        #endregion

        #region ElementsRegistation
        bool ElemNameIsRegistered(string RegName);
        void RegisterElement(UIElement Elem, string RegName);
        object GetElement(string RegName);
        void UnRegisterElement(string RegName);
        #endregion
    }

    public delegate void StringSelectionHandler(object sender, string e);
    public delegate void SelectedMovieChangedHandler(object sender, SelectedMovieChangedArgs e);
    public delegate void SelectedFileChangedHandler(object sender, SelectedFileChangedArgs e);
    public delegate void StatusVarChangedHandler(object sender, StatusVarChangedArgs e);
    public delegate void DisplayPanelChangedHandler(object sender, DisplayPanelChangedArgs e);
    public delegate void GenericValueChangedHandler(object sender, GenericValueChangedArgs e);
    public delegate void ErrorReportHandling(object sender, ErrorReporter e);
    public delegate void StyleCalledHandlrer(object sender, ElementInfo e);
    public delegate void CallEventHandler(object sender);

    public class StatusVarChangedArgs
    {
        public string StatusName { get; set; }
        public string StatusChangedFrom { get; set; }
        public string StatusChangedTo { get; set; }
    }
    public class SelectedMovieChangedArgs
    {
        public string OriginalMovieCode { get; set; }
        public string NewMovieCode { get; set; }
    }
    public class SelectedFileChangedArgs
    {
        public string OriginalFileID { get; set; }
        public string NewFileID { get; set; }
    }
    public class DisplayPanelChangedArgs
    {
        public IPanel OriginalPanel{ get; set; }
        public IPanel NewPanel { get; set; }
    }
    public class GenericValueChangedArgs
    {
        public object OriginalValue { get; set; }
        public object NewValue { get; set; }
    }
}
